package com.zeng.controller;

import com.zeng.common.Constants;
import com.zeng.dao.LeagueTableQueryDao;
import com.zeng.entity.Complaint;
import com.zeng.entity.Complaints;
import com.zeng.entity.Goods;
import com.zeng.entity.Ordersinfo;
import com.zeng.service.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * (Goods)表控制层
 *
 * @author zengfanchao
 * @since 2021-03-17 19:17:03
 */
@RestController
@RequestMapping("adminhome")
public class AdminHomePageController {
    /**
     * 服务对象
     */
    @Resource
    private GoodsService goodsService;
    @Resource
    private ComplaintService complaintService;
    @Resource
    private ComplaintsService complaintsService;
    @Resource
    private UserinfoService userinfoService;
    @Resource
    private OrdersinfoService ordersinfoService;
    @Resource
    private LeagueTableQueryDao leagueTableQueryDao;


    /**
     * 管理员首页，获取所有数据总览
     *
     * @return
     */
    @GetMapping("adminhomepageAllGoods")
    public List<List<Object>> adminhomepageAllGoods() {
        List<Object> lables = new ArrayList<Object>();
        List<Object> data = new ArrayList<Object>();
        List<HashMap<String, Object>> list = this.leagueTableQueryDao.adminhomepageAllGoods();
        for (HashMap<String, Object> map : list) {
            lables.add(map.get("kname"));
            data.add(map.get("gsum"));
        }
        List<List<Object>> listList = new ArrayList<List<Object>>();
        listList.add(lables);
        listList.add(data);
        return listList;
    }

    /**
     * 用户注册量
     */
    @GetMapping("userSum")
    public Integer usersum() {
        return this.userinfoService.queryCount();
    }

    /**
     * 待处理审核
     */
    @GetMapping("waitRead")
    public Integer waitRead() {
        int sum = 0;
//        用户审核
//        Userinfo userinfo = new Userinfo();
//        userinfo.setDeleteflag(0);
//        userinfo.setUserstate(USER_WAIT);
//        sum += this.userinfoService.queryAll(userinfo).size();
//        申诉审核
        Complaint complaint = new Complaint();
        complaint.setState("未处理");
        sum += this.complaintService.queryAll(complaint).size();
//        投诉审核
        Complaints complaints = new Complaints();
        complaints.setState("未处理");
        sum += this.complaintsService.queryAll(complaints).size();
//        商品审核
        Goods goods = new Goods();
        goods.setDeleteflag(0);
        goods.setIsreview(0);
        sum += this.goodsService.queryAll(goods).size();
        return sum;
    }


    /**
     * 总在售商品
     */
    @GetMapping("isSellGoods")
    public Integer isSellGoods() {
        int sum = 0;
        Goods goods = new Goods();
        goods.setDeleteflag(0);
        goods.setIsreview(1);
        sum += this.goodsService.queryAll(goods).size();
        return sum;
    }

    /**
     * 订单总览
     */
    @GetMapping("orderView")
    public List<Integer> orderView() {
        List<Integer> list = new ArrayList<Integer>();
        int sum = 0;
        Ordersinfo ordersinfo = new Ordersinfo();
        ordersinfo.setGoodssum(Constants.ORDER_STATUS_SUCCESS);
        list.add(this.ordersinfoService.queryAll(ordersinfo).size());
        ordersinfo.setGoodssum(Constants.ORDER_STATUS_RUNING);
        sum += this.ordersinfoService.queryAll(ordersinfo).size();
        ordersinfo.setGoodssum(Constants.ORDER_STATUS_QUEREN1);
        sum += this.ordersinfoService.queryAll(ordersinfo).size();
        ordersinfo.setGoodssum(Constants.ORDER_STATUS_QUEREN2);
        sum += this.ordersinfoService.queryAll(ordersinfo).size();
        list.add(sum);
        ordersinfo.setGoodssum(Constants.ORDER_STATUS_CLOSE);
        list.add(this.ordersinfoService.queryAll(ordersinfo).size());
        list.add(this.ordersinfoService.queryCount());
        return list;
    }

    @GetMapping("adminHomeViewCommentLimit")
    public List<HashMap<String, Object>> adminHomeViewCommentLimit(int offset, int limit) {
        return this.leagueTableQueryDao.adminHomeViewCommentLimit(offset, limit);
    }

    /**
     * 查询本月每天订单量
     * @return
     */
    @GetMapping("adminHomeOrderByM")
    public List<List<Object>> adminHomeOrderByM() {
        List<Object> lables = new ArrayList<Object>();
        List<Object> data = new ArrayList<Object>();
        List<HashMap<String, Object>> list = this.leagueTableQueryDao.adminHomeOrderByM();
        for (HashMap<String, Object> map : list) {
            lables.add(map.get("osum"));
            data.add(map.get("otime"));
        }
        List<List<Object>> listList = new ArrayList<List<Object>>();
        listList.add(lables);
        listList.add(data);
        return listList;
    }
}